package com.zhida.smartcontrol.launch.login;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.jay.tools.utils.SharedUtil;
import com.jay.tools.utils.SoftInputUtils;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.common.Keys;
import com.zhida.smartcontrol.launch.EntryFragment;
import com.zhida.smartcontrol.mvp.MVPBaseFragment;

import java.util.List;

import butterknife.BindViews;
import butterknife.OnClick;

/**
 * author: tanjianpei
 * date: 2019/10/8 008 16:19
 * description: 登录
 */
public class LoginFragment extends MVPBaseFragment<LoginContract.View, LoginPresenter> implements LoginContract.View {
    @BindViews({R.id.et_phone, R.id.et_pass})
    List<EditText> mEtList;

    public static LoginFragment newInstance() {
        Bundle args = new Bundle();
        LoginFragment fragment = new LoginFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected Object getLayout() {
        return R.layout.fragment_login;
    }

    @Override
    protected void initLazy(Bundle savedInstanceState) {
        SharedUtil.putString(Keys.PROJECT_LIST, "");
        mEtList.get(0).setText(SharedUtil.getString(Keys.INPUT_USER, ""));
        mEtList.get(1).setText(SharedUtil.getString(Keys.INPUT_PASS, ""));
    }

    @OnClick({R.id.btn_login})
    public void click(View v) {
        switch (v.getId()) {
            case R.id.btn_login:
                SoftInputUtils.hideSoftInput(getProxyActivity());
                String user = mEtList.get(0).getText().toString().trim();
                String pass = mEtList.get(1).getText().toString().trim();
                mPresenter.login(user, pass);
                break;
        }
    }

    @Override
    public void loginOk() {
        startWithPop(EntryFragment.newInstance());
    }
}
